package com.bw.lib_check_wdy_xin

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.CheckBox
import android.widget.RadioGroup
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.lib_check_wdy_xin.donghua.AnimationActivity
import com.bw.lib_check_wdy_xin.listview.ListCheckActivity

@Route(path = "/check/CheckActivity")
class CheckActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_check)

        //处理系统栏
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        //获取RadioGroup引用
        val check_group_wdy = findViewById<RadioGroup>(R.id.check_group_wdy)

        // 获取CheckBox引用
        val check_box_look_wdy = findViewById<CheckBox>(R.id.check_box_look_wdy)
        val check_sports_wdy = findViewById<CheckBox>(R.id.check_sports_wdy)
        val check_music_wdy = findViewById<CheckBox>(R.id.check_music_wdy)

        // 获取提交按钮引用
        val check_bt_wdy = findViewById<Button>(R.id.check_bt_wdy)

        // 获取ListView复选框按钮引用
        val check_list_wdy = findViewById<Button>(R.id.check_list_wdy)

        //获取查看动画示例引用
        val check_animation_wdy = findViewById<Button>(R.id.check_animation_wdy)

        // 设置提交按钮点击监听器
        check_bt_wdy.setOnClickListener {
            val selectedFruitId = check_group_wdy.checkedRadioButtonId
            val selectedFruit = when (selectedFruitId){
                R.id.check_apple_wdy -> "苹果"
                R.id.check_banana_wdy -> "香蕉"
                R.id.check_orange_wdy -> "橙子"
                else -> "未选择"
            }

            // 获取选中的兴趣爱好
            val interests = mutableListOf<String>()
            if (check_box_look_wdy.isChecked) interests.add("阅读")
            if (check_sports_wdy.isChecked) interests.add("运动")
            if (check_music_wdy.isChecked) interests.add("音乐")

            // 显示选择结果
            val message = """
                选择的水果是: $selectedFruit
                选择的爱好是: ${if (interests.isEmpty()) "未选择" else interests.joinToString(",")}
            """.trimIndent()

            Toast.makeText(this,message,Toast.LENGTH_LONG).show()
        }

        check_list_wdy.setOnClickListener {
            val intent = Intent(this,ListCheckActivity::class.java)
            startActivity(intent)
        }

        check_animation_wdy.setOnClickListener {
            val intent = Intent(this,AnimationActivity::class.java)
            startActivity(intent)
        }
    }
}